
var qTipX = 10; // 弹出窗口位于鼠标左侧的距离。//
var qTipY = 15; // 弹出窗口位于鼠标下方的距离。//
tooltip = {
	name : "qTip",
	offsetX : qTipX,
	offsetY : qTipY,
	tip : null
}

tooltip.init = function() {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if (!tipContainerID) {
		var tipContainerID = this.name;
	}
	var tipContainer = document.getElementById(tipContainerID);
	if (!tipContainer) {
		tipContainer = document.createElementNS ? document.createElementNS(
				tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
		tipContainer.setAttribute("style", "");
		tipContainer.style.display = "none";
		document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById)
		return;
	this.tip = document.getElementById(this.name);
}

tooltip.setToolTip = function(evt,picPath) {
	tooltip.show(picPath);
	tooltip.move(evt);
}

tooltip.move = function(evt) {
	var x = 0, y = 0;
	var e=evt||window.Event;
	var bodyW = document.body.clientWidth;// 网页可见区域宽
	var bodyH = document.body.clientHeight;// 网页可见区域高
	var scrollTop = (document.documentElement && document.documentElement.scrollTop)
			? document.documentElement.scrollTop
			: document.body.scrollTop; // 网页被卷去的高
	var tipW = this.tip.clientWidth;
	var tipH = this.tip.clientHeight;
	if (!!window.ActiveXObject) {// IE
		x = document.documentElement.scrollLeft
				? document.documentElement.scrollLeft
				: document.body.scrollLeft;
		y = document.documentElement.scrollTop
				? document.documentElement.scrollTop
				: document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
	} else {// 其他浏览器
		x = e.pageX;
		y = e.pageY;
	}

	if (x > bodyW - tipW - this.offsetX) {
		x = x - tipW - this.offsetX;
	} else {
		x = x + this.offsetX;
	}
	if (y >= bodyH + scrollTop - tipH - this.offsetY) {
		y = bodyH + scrollTop - tipH - 2;
	} else {
		y = y + this.offsetY;
	}
	this.tip.style.left = x + "px";
	this.tip.style.top = y + "px";
}

tooltip.show = function(text) {
	if (!this.tip)
		return;
	var strTab ="";
		text = text.replace(/\n/g, "<br>").replace(/\0x13/g, "<br>").replace(
			/\{(.[^\{]*)\}/ig, "");
	strTab="<table id='toolTipTalbe' style='border:1px solid #007db5;line-height:140%;border-collapse: collapse;'>"
			+ "<tr><img src='" + text + "'></tr>" + "</table>";
	
	this.tip.innerHTML = strTab;
	this.tip.style.cssText = "display:block;position:absolute;z-index:10001;";
	if (this.tip.clientWidth >= document.documentElement.clientWidth) {
		this.tip.style.width = document.documentElement.clientWidth + "px";
	}
}

tooltip.hide = function() {
	if (!this.tip)
		return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

window.onload = function() {
	tooltip.init();
}